package com.fs.consumer;

/**
 * @author ：hyq
 * @date ：Created in 2020/7/8 17:49
 * @description：
 * @modified By：
 */

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 *
 * @date 2019-07-30 14:44
 **/
@Component
@Slf4j
public class AlarmListener {

    /**
     *
     */
    private static final String TOPIC = "alarm";

    @Autowired
    KafkaTemplate template;

    /**
     * 消费告警消息。
     */
    //@KafkaListener(topics = {TOPIC})
    public void AlarmMessageListener(ConsumerRecord<?, ?> record) {
            Optional<?> kafkaMessage = Optional.ofNullable(record.value());
            if (kafkaMessage.isPresent()) {
                System.out.println("================="+record.value().toString());
            }
    }

//    @KafkaListener(topics = {TOPIC})
//    public void AlarmMessageListener(ConsumerRecord<?, ?> record, Acknowledgment acknowledgment) {
//
//        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
//        if (kafkaMessage.isPresent()) {
//            System.out.println(record.value().toString());
//            acknowledgment.acknowledge();
//        }
//    }
}

